package com.wing.file.controller.admin;

import com.wing.file.service.MinIOFileStorageService;
import com.wing.web.annotation.AuthPass;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(value = "Minio文件管理", tags = "Minio文件管理")
@AuthPass
@CrossOrigin
@RestController
@RequestMapping("minio/admin/file")
public class MinioController {

    @Autowired
    private MinIOFileStorageService minIOFileStorageServiceImpl;

    @ApiOperation(value = "minio上传文件")
    @PostMapping("/fileupload")
    public String fileupload(@RequestParam MultipartFile file){
        // 检查multipartFile是否为空
        if (file == null || file.isEmpty()) {
            return "文件为空，无法处理。";
        }
        // 上传到MinIO服务器
        // 这里的"common"是前缀
        return minIOFileStorageServiceImpl.uploadFileByMultipartFile("common", file.getOriginalFilename(), file);
    }

}